<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        s = "loveleetcode"

        var firstUniqChar = function(s) {
            for (let i=0;i<s.length;i++){
                var n = s.charAt(i)
                if(s.indexOf(n)==s.lastIndexOf(n)){
                    return i
                }
            }
            return -1
        };

        console.log(firstUniqChar(s));

    </script>
</body>
</html>